//
//  EditInformationViewController.m
//  Fireball
//
//  Created by 俞渊华 on 2017/12/13.
//  Copyright © 2017年 俞渊华. All rights reserved.
//

#import "EditInformationViewController.h"
#import "EditingViewController.h"

@interface EditInformationViewController ()
<
UITableViewDelegate,
UITableViewDataSource,
UIImagePickerControllerDelegate,
UINavigationControllerDelegate
>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSArray *titleArray;

@end

@implementation EditInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"编辑资料";
    self.view.backgroundColor = [UIColor xm_splitlineColor];
    self.titleArray = @[@"头像",@"昵称",@"性别",@"生日",@"个人简介"];
    
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(8, 0, 0, 0));
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArray.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * identifier = @"identifier";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.text = self.titleArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString * titleText = self.titleArray[indexPath.row];
    if ([titleText isEqualToString:@"昵称"] ||[titleText isEqualToString:@"个人简介"] ) {
        EditingViewController * editingVC = [[EditingViewController alloc] init];
        editingVC.titleText = titleText;
        [self.navigationController pushViewController:editingVC animated:YES];
        
    }else if ([titleText isEqualToString:@"头像"]){
        [self uploadUserLogo];
    }else if ([titleText isEqualToString:@"性别"]){
        
    }else if ([titleText isEqualToString:@"生日"]){
        
    }

}

-(void)uploadUserLogo{
    ACAlertController * alert = [[ACAlertController alloc]initWithActionSheetTitles:@[@"相册",@"拍照"]
                                                                        cancelTitle:@"取消"];
    [alert clickActionButton:^(NSInteger index) {
        NSUInteger sourceType = 0;
        
        switch (index) {
            case 0://相册
                sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                break;
            case 1://拍照
                sourceType = UIImagePickerControllerSourceTypeCamera;
                break;
            default:
                break;
        }
        
        UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
        //设置图像选取控制器的来源模式为相机模式
        
        imagePickerController.sourceType = sourceType;
        imagePickerController.allowsEditing = YES;
        //设置委托对象
        imagePickerController.delegate = self;
        
        imagePickerController.navigationBar.tintColor = [UIColor blackColor];
        [self presentViewController:imagePickerController animated:YES completion:nil];
        
    }];
    [alert show];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    [picker dismissViewControllerAnimated:YES completion:^{
    }];
    
    UIImage *editedImge = info[UIImagePickerControllerEditedImage];
}

- (UITableView *)tableView{
    if (!_tableView) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.tableFooterView = [UIView new];
        tableView.scrollEnabled = NO;
        _tableView = tableView;
    }
    return _tableView;
}

@end






